package com.ciwong.epaper.modules.scan.util;

import android.support.v4.view.ViewPager;
import android.view.View;

/**
 * Created by res-zwyan on 2015/9/17.
 */
public class DepthPageTransformer implements ViewPager.PageTransformer
{
    private static final float MIN_SCALE = 0.4f;
    private static final float MIN_ALPHA = 0.5f;

    public void transformPage(View view, float position) {
        if (position < -1) { // [-Infinity,-1)
            // This page is way off-screen to the left.
            view.setScaleY(MIN_SCALE);
            view.setScaleX(MIN_SCALE);
            view.setAlpha(MIN_ALPHA);
        } else if (position == 0) { // [-1,0]
            // Use the default slide transition when moving to the left page
            view.setScaleY(1);
            view.setScaleX(1);
            view.setAlpha(1);
        } else if (position <= 1) { // (0,1]
            // Fade the page out.

            // Counteract the default slide transition

            // Scale the page down (between MIN_SCALE and 1)
            float scaleFactor = MIN_SCALE
                    + (1 - MIN_SCALE) * (1 - Math.abs(position));
            float alphaFactor = MIN_ALPHA
                    + (1 - MIN_ALPHA) * (1 - Math.abs(position));
            view.setScaleY(scaleFactor);
            view.setScaleX(scaleFactor);
            view.setAlpha(alphaFactor);
        } else { // (1,+Infinity]
            // This page is way off-screen to the right.
            view.setScaleY(MIN_SCALE);
            view.setScaleX(MIN_SCALE);
            view.setAlpha(MIN_ALPHA);
        }
    }
}
